package com.zsl.swing.redis.desktop.struct;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class FixedArrayList<T> {

    private List<T> fixedList;

    private int fixedSize;

    public FixedArrayList(int fixedSize){
        this.fixedSize = fixedSize;
        this.fixedList = new ArrayList<>();
    }

    public int size() {
        return this.fixedList.size();
    }

    public boolean isEmpty() {
        return this.fixedList.isEmpty();
    }

    public boolean contains(Object o) {
        return this.fixedList.contains(o);
    }

    public Iterator<T> iterator() {
        return this.fixedList.iterator();
    }

    public Object[] toArray() {
        return this.fixedList.toArray();
    }

    public <T1> T1[] toArray(T1[] a) {
        return this.fixedList.toArray(a);
    }

    public synchronized boolean add(T t) {
        this.fixedList.add(t);
        if(this.fixedList.size() > fixedSize){
            this.fixedList.remove(0);
        }
        return true;
    }

    public synchronized T get(int index){
        return this.fixedList.get(index);
    }

    public boolean remove(Object o) {
        return this.fixedList.remove(o);
    }

    public boolean containsAll(Collection<?> c) {
        return this.fixedList.containsAll(c);
    }

    public boolean addAll(Collection<? extends T> c) {
        return this.fixedList.addAll(c);

    }

    public boolean removeAll(Collection<?> c) {
        return this.fixedList.removeAll(c);
    }

    public boolean retainAll(Collection<?> c) {
        return this.fixedList.retainAll(c);
    }

    public void clear() {
        this.fixedList.clear();
    }

}
